package com.baidu.yyb.MMKV;

import android.content.Context;

import com.lt.utils.Activity.AndroidConfig;
import com.tencent.mmkv.MMKV;

import java.util.HashMap;
import java.util.Map;


/**
 * 小数据存储
 * @author LiuTong
 */
public class MmKvUtils {
    private static volatile MmKvUtils instance;
    private Map<String, MMKV> mMkvMap = new HashMap<>();

    private MmKvUtils(){
        MMKV.initialize(AndroidConfig.getInstance().getAppContext());
    }

    public static MmKvUtils getInstance() {
        if(instance == null){
            synchronized (MmKvUtils.class){
                if(instance == null){
                    instance = new MmKvUtils();
                }
            }
        }
        return instance;
    }

    /***
     * 只初始化一次
     * @param context
     */
    public void init(Context context){

    }

    public MMKV getMMkvWith(String name){
        MMKV mmkv ;
        if(mMkvMap.containsKey(name) && mMkvMap.get(name) != null){
            return mMkvMap.get(name);
        }
        mmkv = MMKV.mmkvWithID(name);
        mMkvMap.put(name,mmkv);

        return mmkv;
    }

}
